﻿//***********************************************************************
// Assembly         : IGolovkine.AoA.Core
// Author           : Ilia
// Created          : 06-11-2011
//
// Last Modified By : Ilia
// Last Modified On : 01-04-2010
// Description      : 
//
// Copyright        : (c) Microsoft. All rights reserved.
//***********************************************************************
using System;
using System.Reactive.Linq;

namespace IGolovkine.AoA
{
    public static class MessageObservableEX
    {
        public static IObservable<T> OfType<T>(this IObservable<Message> messages) where T: Message
        {
            return from m in messages where m is T select m as T;
        }

        //
        // This is why we need Contravariance!
        //
        public static IObservable<T> OfType<T>(this IObservable<Tcp.TcpMessage> messages) where T : Tcp.TcpMessage
        {
            return from m in messages where m is T select m as T;
        }

        public static IObservable<T> OfType<T>(this IObservable<Tcp.TcpConnectionMessage> messages) where T : Tcp.TcpConnectionMessage
        {
            return from m in messages where m is T select m as T;
        }
    }
}
